﻿@using TS2015.Models
@model TS2015.Models.TbTinTuc

<h4 style="margin:0">Chi tiết tin tức</h4>
<hr />

@using (Html.BeginForm("ThemHoacSuaTinTuc", "QuanTriTrang",FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    @Html.HiddenFor(m => m.MaTinTuc)

    <div class="form-horizontal col-lg-11">
        <div class="form-group">
            <label for="TieuDe" class="control-label col-md-3 col-lg-2 col-xs-2">Tiêu đề:</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                @Html.TextBoxFor(m => m.TieuDe, new { @class = "form-control", placeholder = "Nhập mô tả nội dung bài viết..." })
                @Html.ValidationMessageFor(model => model.TieuDe)
            </div>
        </div>

        <div class="form-group">
            <label for="displayAnhDaiDien" class="control-label col-md-3 col-lg-2 col-xs-2">Ảnh đại diện:</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                <img id="displayAnhDaiDien" src='/Uploads/img/@(Model.AnhDaiDien ?? "no_image.png")' alt="@(Model.TieuDe ?? "")" class="img-thumbnail img-responsive" style="max-height:250px;" />
                @*<input type="file" name="AnhDaiDien" class="hide" id="AnhDaiDien" />*@
                @Html.TextBoxFor(m => m.AnhDaiDien, new { type = "file" , @class="hide", id="AnhDaiDien"})
                @Html.ValidationMessageFor(model => model.AnhDaiDien)
            </div>
        </div>

        <div class="form-group">
            <label for="MoTa" class="control-label col-md-3 col-lg-2 col-xs-2">Mô tả:</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                @Html.TextAreaFor(m => m.MoTa, new { @class = "form-control", placeholder = "Nhập mô tả nội dung bài viết...", rows = "3" })
                @Html.ValidationMessageFor(model => model.MoTa)
            </div>
        </div>

        <div class="form-group">
            <label for="MoTa" class="control-label col-md-3 col-lg-2 col-xs-2">Từ khóa (SEO):</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                @Html.TextAreaFor(m => m.TuKhoa, new { @class = "form-control", placeholder = "Nhập từ khóa bài viết...", rows = "2" })
                @Html.ValidationMessageFor(model => model.TuKhoa)
            </div>
        </div>

        <div class="form-group">
            <label for="NoiDung" class="control-label col-md-3 col-lg-2 col-xs-2">Nội dung:</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                @Html.TextAreaFor(m => m.NoiDung, new { @class = "form-control", placeholder = "Nhập nội dung bài viết..." })
                @Html.ValidationMessageFor(model => model.NoiDung)
            </div>
        </div>

        <div class="form-group">
            <label for="MaLoaiTinTuc" class="control-label col-md-3 col-lg-2 col-xs-2">Thể loại:</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                @Html.DropDownList("MaTheLoai", (SelectList)ViewBag.TheLoai, "Chọn thể loại", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.MaTheLoai)
            </div>
        </div>

        <div class="form-group">
            <label for="TrangThai" class="control-label col-md-3 col-lg-2 col-xs-2">Trạng thái:</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                @Html.EnumDropDownListFor(m => m.TrangThai, "Chọn trạng thái", new { @class = "form-control" })
                @*@Html.DropDownList("TrangThai", new SelectList(Enum.GetValues(typeof(DuLieuChung.TrangThai))), "Chọn trạng thái", new { @class = "form-control" })*@
                @Html.ValidationMessageFor(model => model.TrangThai)
            </div>
        </div>

        <div class="form-group">
            <label for="NoiBat" class="control-label col-md-3 col-lg-2 col-xs-2">Tin nổi bật:</label>
            <div class="col-lg-10 col-md-9 col-xs-10">
                @Html.CheckBoxFor(m => m.NoiBat)
            </div>
        </div>
    </div>
    
    <hr style="clear:both" />
    <div class="col-lg-12">
        <button type="submit" class="btn btn-danger">Lưu</button>
        <a href="#" class="btn btn-danger">Quay lại</a>
    </div>
    <br />
}

<script src="~/Content/tinymce/tinymce.min.js"></script>
<script>
    tinymce.init({
        selector: "textarea#NoiDung",
        theme: "modern",
        //width: 300,
        height: 400,
        language: 'vi_VN',
        paste_data_image:true,
        fontsize_formats: "8pt 9pt 10pt 11pt 12pt 13pt 14pt 15pt 16pt 18pt 24pt 36pt",
        plugins: [
             "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
             "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
             "save table contextmenu directionality emoticons template paste textcolor"
        ],
        paste_data_images: true,
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify |" +
        "bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons | fontselect | fontsizeselect",
        style_formats: [
             { title: 'Bold text', inline: 'b' },
             { title: 'Red text', inline: 'span', styles: { color: '#ff0000' } },
             { title: 'Red header', block: 'h1', styles: { color: '#ff0000' } },
             { title: 'Example 1', inline: 'span', classes: 'example1' },
             { title: 'Example 2', inline: 'span', classes: 'example2' },
             { title: 'Table styles' },
             { title: 'Table row 1', selector: 'tr', classes: 'tablerow1' }
        ]
    });

    function OpenUpload(fileUpload)
    {
        $(fileUpload).click();
    }

    $('#displayAnhDaiDien').click(function ()
    {
        $('#AnhDaiDien').click();
    });
    $('#AnhDaiDien').change(function ()
    {
        readURL(this, '#displayAnhDaiDien');
    });

    function readURL(input, imgAnhDaiDien)
    {
        if (input.files && input.files[0])
        {
            var reader = new FileReader();
            reader.onload = function (e)
            {
                $(imgAnhDaiDien).attr('src', e.target.result);
            }
            reader.readAsDataURL(input.files[0]);
        }
    }
</script>